<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c"%>
<%@ taglib uri="/WEB-INF/tld/ui.tld" prefix="ui"%>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>汽贸城新增页面</title>
<jsp:include page="../../import.jsp" flush="true" />
</head>
<body class="iframeBody">
	<div class="Wrapper">
		<div id="pageInTab" class="pageInTab">
			<div tabid="tabA" title="基本信息" lselected="true">
				<form id="formSet1">
					<div class="fieldset1 tabel_col clearFix">
						<div class="caption">
							<span class="title">基本信息</span>
						</div>
						<div class="fieldBox col_33">
							<div class="label">姓名</div>
							<div class="field">
								<input name="atNm" id="atNm" type="text" class="ui-textbox" validate="{required:true}"> 
								<span class="requiredSymbol">*</span>
							</div>
						</div>
						<div class="fieldBox col_66_auto">
							<div class="label">区域</div>
							<div class="field">
								<jsp:include page="../../system/sysRegion/region.jsp"
									flush="true">
									<jsp:param name="regionShowLvl" value="2" />
								</jsp:include>
								<span class="requiredSymbol">*</span>
							</div>
						</div>
						<div class="fieldBox col_100_auto">
							<div class="label">合同日期</div>
							<div class="field">
								<input name="beginDt" id="beginDt" type="text" class="ui-textbox" value="" disabled="disabled"> 
									<span>--</span>
								<input name="endDt" id="endDt" type="text" class="ui-textbox" value="" disabled="disabled"/>
								<span class="requiredSymbol">*</span>
							</div>
						</div>
						<div class="fieldBox col_100">
							<div class="label">地址</div>
							<div class="field">
								<input name="atAddr" id="atAddr" type="text" class="ui-textbox" value="">
								<span class="requiredSymbol">*</span>
							</div>
						</div>
						<%-- <div class="fieldBox col_100">
							<div class="label">资料上传</div>
							<div id="fileUpload" class="field">
								<jsp:include page="atcFilesUpload.jsp" flush="true">
									<jsp:param name="filePath" value="/atcBscInfo" />
								</jsp:include>
							</div>
						</div> --%>
						<div class="fieldBox col_100">
							<div id="fileList">
								<jsp:include page="atcFileList.jsp" flush="true">
									<jsp:param name="pkId" value="${id }" />
									<jsp:param name="tabNm" value="ATC_BSC_INFO" />
									<jsp:param name="detailId" value="1" />
								</jsp:include>
							</div>
						</div>
						
						<!-- 隐藏主键、有效期ID -->
		                <div class="fieldBox col_100" style="display:none;">
		                    <div class="field">
		                         <input name="pId" id="pId" type="text" class="ui-textbox" value="${id}">
		                         <!-- 原有效期-控制是否需要修改 -->
		                         <input name="beginDt_base" id="beginDt_base" type="text" class="ui-datepicker" value="">
								 <input name="endDt_base" id="endDt_base" type="text" class="ui-datepicker" value="">
								 <input name="isBegin" id="isBegin" type="text" class="ui-textbox" value="0">
								 <input name="isEnd" id="isEnd" type="text" class="ui-textbox" value="0">
		                    	 <!-- 上传文件使用：系统时间和当前登录人姓名 -->
		                         <input name="sysDate" id="sysDate" type="text" class="ui-textbox" value="${sysDate }">
		                         <input name="loginUsrNm" id="loginUsrNm" type="text" class="ui-textbox" value="${loginUsrNm }">
		                    </div>
		                </div> 
					</div>
					<div class="sqPanel">
						<div class="sqPanel_head inL">
							<span>主要人员信息</span>
						</div>
						<div class="sqPanel_body">
							<div id="ligergrid_A1" class="sq-grid"></div>
						</div>
					</div>
					<div id="historyList" class="fieldset1 tabel_col tabel_col_s clearFix">
						<div class="caption">
							<span class="title">历史记录</span>
						</div>
						<div class="fieldBox col_100">
							<div id="ligergrid_file2" class="sq-grid"></div>
						</div>
					</div>
					<!-- <div class="btnsBox">
						<span id="saveBtn" class="sq-button sq-button-round" onclick="saveAssParkingInfo()">保存</span>
						<span id="closeBtn" class="sq-button sq-button-round" onclick="Remove_navTab()">关闭</span>
					</div> -->
				</form>
			</div>
			<div tabid="tabB" title="相关供应商">
            	<iframe frameborder="0" name="tabB" id="tabB" src=""></iframe>
        	</div>
		</div>
	</div>
</body>
<script type="text/javascript">
var id = '${id}';
var socialGrid;
$(function(){
	initData();
	initSocialGrid();
	//initForm(); 
	initLogInfo();
	initTab();
	$("#formSet1").ligerForm({
        validate : true
	});
	disabledRgnProvCd();
	disabledRgnCityCd();
	liger.get("atNm").setDisabled(true);
	liger.get("atAddr").setDisabled(true);
	liger.get("endDt").setDisabled(true);
});

//初始化表单
function initForm(){
	//绑定change事件
	$("#startDt").ligerDateEditor({
		onChangeDate: function (value) {
		}
	});
	$("#endDt").ligerDateEditor({
		onChangeDate: function (value) {
		}
	});
};
var loadedTabs = [];
//初始化Tab页
function initTab(){
	pageInTab = $("#pageInTab").ligerTab({
        height: 'auto',
        contextmenu: false,
        minIframeHeight: 450,
        onBeforeSelectTabItem: function (tabid) {
        	if(tabid!="tabA"){
                if(!id){
                	top.$.ligerDialog.SQalert({content: "请确认汽贸城基本信息已存在", SQ_type: "warning"});
                	return false;
                }
        	}
        },
        onAfterSelectTabItem: function(tabid) {
            if (loadedTabs.indexOf(tabid)<0) {
            	if(tabid!="tabA"){
                	if(!id){
                		 top.$.ligerDialog.SQalert({content: "请确认汽贸城基本信息已存在", SQ_type: "warning"});
                         return false; 
                	}
            	}
                loadedTabs.push(tabid);
                switch (tabid){
                	case "tabA":
                		debugger
                    	break;
                    case "tabB":
                    	pageInTab.setTabItemSrc(tabid, "<%=path%>/atc/atcBscInfo/toAtcSplDetailPage.do?atcId=" + id);
                        break;
                }
            };
            SetIframe_height();
        }
    });
};
//修改初始化数据
function initData(){
	if(!id){
		return;
	}
	var _url = '<%=path%>/atc/atcBscInfo/getById.do';
		$.ajax({
			type : 'get',
			dataType : 'json',
			data : {
				id : id
			},
			url : _url,
			success : function(msg) {
				if (msg.success == 1) {
					setData(msg.data);//设置数据
				} else {
					$.ligerDialog.SQalert({
						content : msg.info,
						SQ_type : "error"
					});
				}
			}
		});
	}
	//设置页面数据
	function setData(data) {
		$("#atNm").val(data.atNm);
		$("#atAddr").val(data.atAddr);
		//日期处理
    	if(data.beginDt){
    		var date = new Date(data.beginDt);
    		var dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DD);
    		$("#beginDt").val(dateStr);
    		$("#beginDt_base").val(dateStr);
    	}
    	if(data.endDt){
    		var date = new Date(data.endDt);
    		var dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DD);
    		$("#endDt").val(dateStr);
    		$("#endDt_base").val(dateStr);
    	}
		//区域数据处理
		setRgnProvCdUpdataValue(data.rgnPrCd);
		setRgnCityCdUpdataValue(data.rgnCyCd);
		setRegionSelectDataChange();
		//加载日期插件
		//$("#beginDt").trigger("change");
		//$("#endDt").trigger("change") ;
	}
	//证件类型
    var certTypCdListJSON = [];
    <c:if test="${not empty certTypCdListJSON}"> certTypCdListJSON = ${certTypCdListJSON}; </c:if>
	//主要人员信息
    function initSocialGrid() {
		socialGrid = $("#ligergrid_A1").ligerGrid({
			url: '<%=path%>/atc/atcBscInfo/initAtcRlPsnList.do?',
	    	method : 'get',
	    	parms:{atcId:id},
	    	async: false,
	    	columns: [
	  	            {
	  	                display: '联系人姓名(<span class="c_red">*</span>)', name: 'rlNm', width: 150,
	                    validate: function (value) {
	                        if (StringUtils.isEmpty(value)) return "此项为必填项！";
	                    }
					},
	  	            { display: '联系人类型(<span class="c_red">*</span>)', name: 'rlTypCd', width: 140,
						valueField: 'rlTypCd',
		                textField: 'rlTypCdNm',
						render: function (item) {
	                       return item.rlTypCdNm;
	                   },
						validate: function (value) {
						  if (StringUtils.isEmpty(value)) return "此项为必填项！";
						}
	  	            },
	  	            {
	  	               display: '证件类型(<span class="c_red">*</span>)', name: 'certTypCd', width: 140,
	   	  	           
	                   valueField: 'certTypCd',
	                   textField: 'certTypCdNm',
	                   render: function (item) {
	                       return item.certTypCdNm;
	                   },
	                    validate: function (value) {
	                        if (StringUtils.isEmpty(value)) return "此项为必填项！";
	                    }
	  	            },
	  	            {
	  	                display: '证件号(<span class="c_red">*</span>)', name: 'certNo', width: 150,
	                    validate: function (value) {
	                        if (StringUtils.isEmpty(value)) return "此项为必填项！";
	                    }
	  	            },
	                {
	                    display: '联系电话(<span class="c_red">*</span>)', name: 'mp', width: 150,
	                    validate: function (value) {
	                        if (StringUtils.isEmpty(value)) return "此项为必填项！";
	                    }
					},
	  	            { display: '备注', name: 'remark', minWidth: 150},
   	  	        	
	  	        ],
   	  	   usePager: false,
           root: 'rows',
           record: 'total',
           hideLoadButton: true,
           width: '100%',
           height: 180,
           heightDiff: -2,
           enabledEdit: true,
           isScroll: true,
           checkbox: false,
           rownumbers: true,
           allowUnSelectRow: true,
           alternatingRow: false,
           enabledSort:false
		});
	}
	//历史信息
	function initLogInfo(){
		$("#ligergrid_file2").ligerGrid({
			usePager: false,
			url: '<%=path%>/atc/atcBscInfo/getAtcBscInfoLList.do?',
	    	method : 'get',
	    	parms:{atcId:id},
	    	async: false,
	    	columns: [
	    		{ display: '合同有效期', name: 'beginDt', width: 290,
	    			render:function (rowdata, index, value){
	            		var endDt = "";
	            		var startDt = "";
	            		if(null != rowdata.endDt){
	            			var date = new Date(rowdata.endDt);
	            			endDt = DateUtils.formatDate(date, 'yyyy.MM.dd');
	            		}
	            		if(null != value){
	            			var date = new Date(value);
	            			startDt = DateUtils.formatDate(date, 'yyyy.MM.dd');
	            		}
	            		return startDt+"-"+endDt;
	            	}	
	    		},
	            { display: '上传文件名', name: 'fileNm', width: 250,
	    			render: function (rowdata, rowindex, value){
						var h;
						h='<a href="javascript:uploadFileByUrl(';
						h+="'"+rowdata.filePath+"'";
						h+=",'"+rowdata.fileNm+"'";
						h+=')">'+rowdata.fileNm+'</a>';
						return h;
					}	
	            },
	            { display: '上传者', name: 'crtUsrRlNm', width: 220},
	            { display: '上传时间', name: 'crtTm',render:renderDate, width: 290},
	    	],
	    	usePager: false,
	           root: 'rows',
	           record: 'total',
	           hideLoadButton: true,
	           width: '100%',
	           height: 300,
	           heightDiff: -2,
	           enabledEdit: true,
	           isScroll: true,
	           checkbox: false,
	           rownumbers: true,
	           allowUnSelectRow: true,
	           alternatingRow: false,
	           enabledSort:false
		});
	}
	//格式化时间
	function renderDate(rowdata, index, value){
		var dateStr = "";
		if(null != value){
			var date = new Date(value);
			dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DDHHMMSS);
		}
		return dateStr;
	}
	//下载文件方法
	function uploadFileByUrl(_url,_name){
		if(SQ.regs.img.test(_name)){
			alert(_url);
			SQ.imgPreview(_url, true);
		}else{
			alert(_url);
			window.open(_url);
		}
	}
</script>

</html>